function KickTargetRoutine takes nothing returns nothing
	local timer kickTargetTimer = GetExpiredTimer()
	local integer kickTargetTimerId = GetHandleId(kickTargetTimer)
	local unit kickTarget = LoadUnitHandle(udg_HT , kickTargetTimerId , 3)
	local location kickTargetLocation = GetUnitLoc(kickTarget)
	local real kickTargetX = GetLocationX(kickTargetLocation)
	local real kickTargetY = GetLocationY(kickTargetLocation) 
	local real dx = LoadReal(udg_HT , kickTargetTimerId , 4)
	local real dy = LoadReal(udg_HT , kickTargetTimerId , 5)
	local real process = LoadReal(udg_HT , kickTargetTimerId , 6)
	local location newLocation = null
	local location newRealLocation = null
	local boolean end = false
	//--
	if process < 40.0 then
		set process = process + 1.0
		call SaveReal(udg_HT , kickTargetTimerId , 6 , process)
		set newLocation = Location(kickTargetX + dx , kickTargetY + dy)
		call SetUnitPositionLoc(kickTarget , newLocation)
		set newRealLocation = GetUnitLoc(kickTarget)
		if DistanceBetweenPoints(newLocation , newRealLocation) > 5.0 then
			call SetUnitPositionLoc(kickTarget , kickTargetLocation)
			set end = true
		endif
	else
		set end = true
	endif
	if end then
		call PauseTimer(kickTargetTimer)
		call FlushChildHashtable(udg_HT , kickTargetTimerId)
		call DestroyTimer(kickTargetTimer)
	endif
	
	//--
	call RemoveLocation(kickTargetLocation)
	call RemoveLocation(newLocation)
	call RemoveLocation(newRealLocation)
	set kickTargetTimer = null
	set kickTarget = null
	set kickTargetLocation = null
	set newLocation = null
	set newRealLocation = null
endfunction

function KickDamage takes nothing returns nothing
	local unit target = GetEnumUnit()
	local location targetLocation = GetUnitLoc(target)
	local real angle = AngleBetweenPoints(udg_TempCasterLocation , targetLocation)
	local real targetX = GetLocationX(targetLocation)
	local real targetY = GetLocationY(targetLocation)
	local real delta = 800.0 * 0.01 // speed setting
	local real dx = Cos(angle * bj_DEGTORAD) * delta
	local real dy = Sin(angle * bj_DEGTORAD) * delta
	local timer targetTimer = null
	local integer targetTimerId = 0
	//--
	if (IsUnitEnemy(target , udg_TempPlayer) and IsUnitInRangeLoc(target , udg_TempCasterLocation , udg_TempRadius) and not IsUnitType(target , UNIT_TYPE_STRUCTURE) and GetUnitState(target , UNIT_STATE_LIFE) > 0.0 and WithinAngle(angle , udg_TempCastAngle , 90.0)) then
		call UnitDamageTarget(udg_TempDamager , target , udg_TempDamage , true , false , ATTACK_TYPE_NORMAL, DAMAGE_TYPE_COLD , WEAPON_TYPE_METAL_MEDIUM_BASH)
		set targetTimer = CreateTimer()
		set targetTimerId = GetHandleId(targetTimer)
		call SaveUnitHandle(udg_HT , targetTimerId , 3 , target)
		call SaveReal(udg_HT , targetTimerId , 4 , dx)
		call SaveReal(udg_HT , targetTimerId , 5 , dy)
		call SaveReal(udg_HT , targetTimerId , 6 , 0.0) // process
		call TimerStart(targetTimer , 0.01 , true , function KickTargetRoutine)
	endif
	//--
	set target = null
	call RemoveLocation(targetLocation)
	set targetLocation = null
	set targetTimer = null
endfunction

function Trig_Kick_Actions takes nothing returns nothing
	local unit kickingUnit = GetTriggerUnit()
	//--
	set udg_TempDamager = kickingUnit
	set udg_TempPlayer = GetOwningPlayer(kickingUnit)
	set udg_TempDamage = 40.0 + LoadReal(udg_UnitDataHashTable , GetHandleId(kickingUnit) , StringHash("KICK_MASTERY")) * 3.0
	set udg_TempRadius = 150.0
	set udg_TempCasterLocation = GetUnitLoc(kickingUnit)
	set udg_TempSpellTargetLocation = GetSpellTargetLoc()
	set udg_TempCastAngle = AngleBetweenPoints(udg_TempCasterLocation , udg_TempSpellTargetLocation)
	call RemoveLocation(udg_TempSpellTargetLocation)
	set bj_wantDestroyGroup = true
	call ForGroupBJ(GetUnitsInRangeOfLocMatching(udg_TempRadius+70.0, udg_TempCasterLocation , null) , function KickDamage)
	call RemoveLocation(udg_TempCasterLocation)
	call UnitPlayAnimation(kickingUnit , 49 , 2.0 , 0.6)
	call UnitUsedAbilityWithDelta(kickingUnit , 'A00B' , 1.0)
	//--
	set kickingUnit = null
endfunction

function Trig_Kick_Conditions takes nothing returns boolean
	return GetSpellAbilityId() == 'A00B'
endfunction

function InitTrig_Kick takes nothing returns nothing
	local hashtable masteryTable = InitHashtable()
	local integer abilityId = 'A00B'
	//--	
	//call SaveInteger(udg_AbilityDataHashTable , abilityId , StringHash("NEXT_ABILITY") , 'A01X')
	call SaveInteger(udg_AbilityDataHashTable , abilityId , StringHash("HOTKEY") , StringHash("W"))
	call SaveInteger(udg_AbilityDataHashTable , abilityId , StringHash("MASTERY_ID") , StringHash("KICK_MASTERY"))
	call SaveStr(udg_AbilityDataHashTable , abilityId , StringHash("NAME") , "正踢")
	call SaveInteger(udg_AbilityDataHashTable , abilityId , StringHash("MAX_LEVEL") , 1)
	call SaveHashtableHandle(udg_AbilityDataHashTable , abilityId , StringHash("LEVEL_MASTERY_TABLE") , masteryTable)
	//call SaveReal(masteryTable , 1 , 0 , 1.0) //30
	//call SaveReal(masteryTable , 2 , 0 , 2.0) //70
	//call SaveReal(masteryTable , 3 , 0 , 3.0) //120
	
	set gg_trg_Kick = CreateTrigger()
	call TriggerRegisterPlayerForceUnitEvent(gg_trg_Kick , EVENT_PLAYER_UNIT_SPELL_EFFECT)
	call TriggerAddCondition(gg_trg_Kick , Condition(function Trig_Kick_Conditions))
	call TriggerAddAction(gg_trg_Kick , function Trig_Kick_Actions)
endfunction

